package shop.ynubeggar.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import shop.ynubeggar.model.valueobject.CartVO;
import shop.ynubeggar.request.CartItemRequest;
import shop.ynubeggar.service.CartService;

import javax.annotation.Resource;

@Api(tags = "购物车")
@RestController
@RequestMapping("api/cart/v1")
public class CartController {

    @Resource
    CartService cartService;

    @ApiOperation(value = "新增",notes = "添加到购物车")
    @PostMapping("add")
    public void addGoodsToCart(@ApiParam(value = "购物车单项") @RequestBody CartItemRequest cartItemRequest){
        cartService.addToCart(cartItemRequest);
    }

    @ApiOperation(value = "清空",notes = "清空购物车")
    @DeleteMapping("clear")
    public void clearCart(){
        cartService.delAllCartItems();
    }

    @ApiOperation(value = "更改商品数量",notes = "更改购物车商品数量")
    @PostMapping("update")
    public void updateCart(@ApiParam(value = "购物车单项") @RequestBody CartItemRequest cartItemRequest){
        cartService.updateCartItem(cartItemRequest);
    }

    @ApiOperation(value = "列表",notes = "查看购物车")
    @GetMapping("cart")
    public CartVO viewCart(){
        return cartService.viewCart();
    }














}
